<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 30px;
            height: 30px;
            line-height: 30px;
            background-color: #000;
            color: #fff;
            float: left;
            margin: 3px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="hour">1</div>
    <div class="minute">2</div>
    <div class="second">3</div>
    <script>
        var hour = document.querySelector('.hour');
        var minute = document.querySelector('.minute');
        var second = document.querySelector('.second');
        var inputTime = +new Date('2021-8-5 19:00:00');//用户输入的时间
        //先调用一次函数 防止第一次刷新页面有空白
        countDown();
        //开启定时器
        setInterval(countDown, 1000);
        function countDown() {
            var nowTime = +new Date(); //返回的是当前时间总的毫秒数
            var times = (inputTime - nowTime) / 1000; //求得是秒数
            var h = parseInt(times / 60 / 60 % 24); //时
            h = h < 10 ? '0' + h : h;
            hour.innerHTML = h;
            var m = parseInt(times / 60 % 60); //分
            m = m < 10 ? '0' + m : m;
            minute.innerHTML = m;
            var s = parseInt(times % 60); //秒
            s = s < 10 ? '0' + s : s;
            second.innerHTML = s;
        }
    </script>
</body>

</html>